package com.example.kotin.myfragment;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.view.animation.DecelerateInterpolator;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class ScaleXYAnimator {
    private volatile static ScaleXYAnimator inStance;

    private ScaleXYAnimator() {
    }

    public static ScaleXYAnimator getInsatance() {
        if (inStance == null) {
            synchronized (ScaleXYAnimator.class) {
                if (inStance == null) {
                    inStance = new ScaleXYAnimator();

                }
            }
        }
        return inStance;
    }

    public void animatorScaleXYR(RelativeLayout r) {
        //加入缩放动画
        AnimatorSet animatorSet = new AnimatorSet();
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(r, "scaleX", 0, 1f);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(r, "scaleY", 0, 1f);
        animatorSet.setDuration(500);
        animatorSet.setInterpolator(new DecelerateInterpolator());
        animatorSet.play(scaleX).with(scaleY);//两个动画同时开始
        animatorSet.start();
    }

    public void endAnimatorScaleXYR(RelativeLayout r) {
        //加入缩放动画
        AnimatorSet animatorSet = new AnimatorSet();
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(r, "scaleX", 1f, 0);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(r, "scaleY", 1f, 0);
        animatorSet.setDuration(500);
        animatorSet.setInterpolator(new DecelerateInterpolator());
        animatorSet.play(scaleX).with(scaleY);//两个动画同时开始
        animatorSet.start();
    }

    public void animatorScaleXYL(LinearLayout l) {
        //加入缩放动画
        AnimatorSet animatorSet = new AnimatorSet();
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(l, "scaleX", 0, 1f);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(l, "scaleY", 0, 1f);
        animatorSet.setDuration(500);
        animatorSet.setInterpolator(new DecelerateInterpolator());
        animatorSet.play(scaleX).with(scaleY);//两个动画同时开始
        animatorSet.start();
    }
}
